package com.minxi.jsp.controtroller;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class JspServlet extends HttpServlet {

    public static void main(String[] args) throws Exception {
        //注册驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //获取连接
        String url="jdbc；mysql;//127.0.0.1:3306/student?serverTimezone=Asia/Shanghai";
        String userName="root";
        String passWord="123456";
        Connection conn = DriverManager.getConnection(url,userName,passWord);
        //定义sql
        String sql ="update user_info set user_name = '刘小东' where id = 1;";
        //获取执行sql对象
        Statement stmt = conn.createStatement();
        //执行sql
        int count = stmt.executeUpdate(sql);
        //执行结果
        System.out.println(count);
        //释放资源
        stmt.close();
        conn.close();

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String parameter = req.getParameter("userName");
        System.out.println(parameter);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
